package com.lkm.market2_0.m_imple.steelyardserver.server.cmd_handle;

import android.os.Handler;
import android.os.Looper;

import com.lkm.frame.P;
import com.lkm.javatool.StringHelp;
import com.lkm.market2_0.ExpandConfig;
import com.lkm.market2_0.help.UIP;
import com.lkm.market2_0.m.steelyarddata.SteelyardDataModule;
import com.lkm.market2_0.m.steelyardserver.OnSteelyardKeyEvent;
import com.lkm.market2_0.m.steelyardserver.SteelyardServerModule;
import com.lkm.market2_0.m_imple.steelyardserver.server.CMDEntity;
import com.lkm.market2_0.m_imple.steelyardserver.server.ICMDHandle;
import com.lkm.market2_0.m_imple.steelyardserver.server.AbsReceiverDataHandle;



public class CMDKeyHandle implements ICMDHandle {

    SteelyardDataModule mSteelyardDataModule;
    SteelyardServerModule mSteelyardServerModule;

    Handler handler = null;

    public CMDKeyHandle() {
        handler = new Handler(Looper.getMainLooper());
        mSteelyardDataModule = ExpandConfig.instance.getModuleManager().loadModule(SteelyardDataModule.class);
        mSteelyardServerModule = ExpandConfig.instance.getModuleManager().loadModule(SteelyardServerModule.class);
    }

    @Override
    public AbsReceiverDataHandle handle(CMDEntity cmdEntity) {

        if (mSteelyardDataModule == null)
            mSteelyardDataModule = ExpandConfig.instance.getModuleManager().loadModule(SteelyardDataModule.class);

        







//        mSteelyardDataModule.steelyardHeartbeatCollect(cmdEntity.getSteelyardMac(), System.currentTimeMillis(), !true, version, steelyardNumno);



        if (P.isDebug()) {
            String log = "收到keyCode" + cmdEntity.getNum();

            P.p("=====" + log);
            if (UIP.isPrint()) {
                UIP.p(log, cmdEntity.getSteelyardMac());
            }
        }

        if (ExpandConfig.instance.isUI()) {
            
            OnSteelyardKeyEvent.sendKey(cmdEntity.getNum(),handler);
            if (!StringHelp.isEmpty(cmdEntity.getSteelyardMac())) {
                mSteelyardServerModule.tickOK_block(cmdEntity.getSteelyardMac());
            }
        }else {
            if (!StringHelp.isEmpty(cmdEntity.getSteelyardMac())) {

                OnSteelyardKeyEvent.sendKey(cmdEntity.getNum(),handler);
//            LinkBus.sendBroadcast(new OnSteelyardKeyEvent(cmdEntity.getNum()));

                mSteelyardServerModule.tickOK_block(cmdEntity.getSteelyardMac());


//            SteelyardInfo steelyardInfo = mSteelyardDataModule.getSteelyardInfo(cmdEntity.getSteelyardMac());


////                OrganizationInfo organizationInfo = AppDataCache.getInstance().getOrganizationEntity(steelyardInfo.getOrg());



            }
        }




        return null;
    }


}
